package com.lzw.cpvideoplayer.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.lzw.cpvideoplayer.R;
import com.lzw.cpvideoplayer.adapter.MyBaseAdapter;
import com.lzw.cpvideoplayer.data.HeadData;
import com.lzw.cpvideoplayer.data.TitleData;
import com.lzw.cpvideoplayer.mvp.presenter.VideoPresenter;
import com.lzw.cpvideoplayer.mvp.view.BaseActivity;
import com.lzw.cpvideoplayer.mvp.view.IBaseView;
import com.lzw.cpvideoplayer.mvp.view.LoadDiaLog;
import com.lzw.cpvideoplayer.ulit.OnItemClickLiner;
import com.lzw.cpvideoplayer.ulit.Ulit;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class VideoMainActivity extends BaseActivity<IBaseView, VideoPresenter> implements IBaseView<HeadData>{
    private static final String TAG = "VideoMainActivity";
    private RecyclerView mHomeRecyView;
    private MyBaseAdapter mAdapter;
    int countMax;
    int count;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_main);

        initView();
    }

    private void initView() {
       //请求数据
        presenter.fatch(VideoMainActivity.this, Ulit.VideoType_URL);
        //
        mHomeRecyView = findViewById(R.id.video_home_recyview);

    }

    @Override
    public VideoPresenter createPresenter() {
        return new VideoPresenter();
    }

    @Override
    public void ShowViewData(HeadData data) {
        List<TitleData> list = new ArrayList<>();
        Collections.addAll(list, data.getData());
       // Log.e(TAG, "ShowViewData: "+data.getData()[0].getTitle() );
        mAdapter = new MyBaseAdapter(list,VideoMainActivity.this);
        mHomeRecyView.setLayoutManager(new LinearLayoutManager(VideoMainActivity.this));
        mHomeRecyView.setAdapter(mAdapter);
        //添加最后一行 显示页数
        TitleData end = new TitleData();
        end.setType(1);
        list.add(end);
        mAdapter.setOnItemClickLiner(new OnItemClickLiner() {
            @Override
            public int OnItemClick(View v, int p) {

                return 0;
            }
        });
       // Log.e(TAG, "ShowViewData: "+list.get(0).getTitle());
    }
}